package cn.edu.jxau.test;

import java.util.Objects;
import java.util.Vector;

import cn.edu.jxau.util.LinkedQueue;
import cn.edu.jxau.util.Queue;

/**
 * @author Fudashi
 */
public class Main {

	public static void main(String[] args) {

		System.out.println(pow(2, -4));
	}

	private static double pow(double base, int exp) {

		if (exp == 0) { // 任何数的0次幂都是1
			return 1;
		}
		if (equals(base, 0) && exp < 0) { // 负数的负次幂
			return Double.POSITIVE_INFINITY;
		}
		double result = pow0(base, Math.abs(exp));
		if (exp < 0) {
			return 1 / result;
		} else {
			return result;
		}
	}

	private static double pow0(double base, int exp) {

		if (exp == 1) {
			return base;
		}
		double result = pow0(base, exp >> 1);
		result = result * result;
		if ((exp & 1) == 1) {
			result = result * base;
		}
		return result;
	}

	private static boolean equals(double a, double b) {

		return (Math.abs(a - b) < 0.00000001) ? true : false;
	}
}